
package fileby.ctrl.transferhandlers.impl;

import com.google.inject.Inject;
import fileby.ctrl.transferhandlers.ITransferHandlerProvider;
import fileby.core.TransferHandlerType;
import fileby.model.IFavoriteManager;
import fileby.model.IFileManager;
import fileby.model.IMagicBoxManager;
import fileby.model.ISelectionManager;
import fileby.model.ISourceHandler;
import javax.swing.TransferHandler;

/**
 *
 * @author Ludwig Kjellstrom
 */
public class TransferHandlerFactory implements ITransferHandlerProvider{

    private IFileManager fileManager;
    private ISourceHandler sourceHandler;
    private ISelectionManager selectionManager;
    private IFavoriteManager favoriteManager;
    private IMagicBoxManager magicBoxManager;

    @Inject
    public TransferHandlerFactory(IFileManager fileManager,
            ISourceHandler sourceHandler, ISelectionManager selectionManager,
            IFavoriteManager favoriteManager, IMagicBoxManager magicBoxManager){
        this.fileManager = fileManager;
        this.sourceHandler = sourceHandler;
        this.selectionManager = selectionManager;
        this.favoriteManager = favoriteManager;
        this.magicBoxManager = magicBoxManager;
    }

    public TransferHandler create(TransferHandlerType transferHandlerType){
        switch(transferHandlerType){
            case BREAD_CRUMB:
                return new BreadcrumbTransferHandler(fileManager);
            case FAVORITE:
                return new FavoriteTransferHandler(favoriteManager);
            case ITEM_PANEL:
                return new ItemPanelTransferHandler(fileManager, sourceHandler,
                        selectionManager);
            case MAGIC_BOX:
                return new MagicBoxTransferHandler(magicBoxManager);
            case TAB_COMPONENT:
                return new TabComponentTransferHandler(fileManager);
            case TAB_CONTENT:
                return new TabContentTransferHandler(fileManager);
            default:
                System.err.println(transferHandlerType.toString() + ": no such TransferHandler available.");
        }
        throw new Error("Tried to create a TransferHandler this factory don't support.");
    }

}
